﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ImageAppDataModels;
using BrainTechLLC;
using BrainTechLLC.ThreadSafeObjects;
using ImageAppViewModels;
using System;

namespace WpfImageDuplicates
{
    /// <summary>
    /// Interaction logic for FileImageGroupViewControl.xaml
    /// </summary>
    public partial class FileImageGroupViewControl : UserControl
    {
        public static readonly DependencyProperty FileImageGroupViewModelProperty =
            DependencyProperty.Register("FileImageGroupViewModel", typeof(FileImageGroupViewModel), typeof(FileImageGroupViewControl), new PropertyMetadata(null, OnFileImageGroupViewModelPropertyChanged));

        public FileImageGroupViewModel FileImageGroupViewModel
        {
            get { return (FileImageGroupViewModel)GetValue(FileImageGroupViewModelProperty); }
            set { SetValue(FileImageGroupViewModelProperty, value); }
        }

        private static void OnFileImageGroupViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FileImageGroupViewControl source = d as FileImageGroupViewControl;
            FileImageGroupViewModel vNew = e.NewValue as FileImageGroupViewModel;
            FileImageGroupViewModel vOld = e.OldValue as FileImageGroupViewModel;
            source.UpdateFileImageGroupViewModel(vNew, vOld);
        }

        private void UpdateFileImageGroupViewModel(FileImageGroupViewModel viewModel, FileImageGroupViewModel viewModelOld)
        {
            FileImageGroupViewModel = viewModel;

            // Let the UI bind to the view-model.
            this.DataContext = FileImageGroupViewModel;
        }

        public FileImageGroupViewControl()
        {
            InitializeComponent();
        }        
    }
}
